<?php

class Keluar extends Controller {
	var $data;

	function Keluar()
	{
		parent::Controller();
		$this->load->model('Login');
    $this->load->helper("url");
		$this->data["base"] = $this->config->item('base_url');
    session_start();
	}
	
	function index()
	{
	if(getenv("HTTP_CLIENT_IP")) { 
			$ipad = getenv("HTTP_CLIENT_IP"); 
		} elseif(getenv("HTTP_X_FORWARDED_FOR")) { 
			$ipad = getenv("HTTP_X_FORWARDED_FOR"); 
		} else { 
			$ipad = getenv("REMOTE_ADDR"); 
		
	}
		$ipad = substr($ipad, 0,14);
		$translog_id = $this->Login->show_id_trans_log()->row();
		$this->xd = $translog_id->id + 1;
		$this->tgl = date('Y-m-d H:i:s');
    
	if(isset($_SESSION['intern_audit']) and isset($_SESSION['name'])) {
		$this->id = $_SESSION["name"];
		  $insert_log = array('id' => $this->xd,
							'user_id' =>$this->id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('logout'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
			//insert ke table trans log
			$this->Login->insert_log($insert_log);
		
		
		unset($_SESSION['intern_audit']);
	}
	else if(isset($_SESSION['second_consult']) and isset($_SESSION['name'])) {
		$this->id = $_SESSION["name"];
		  $insert_log = array('id' => $this->xd,
							'user_id' =>$this->id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('logout'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
			//insert ke table trans log
			$this->Login->insert_log($insert_log);
		
		unset($_SESSION['second_consult']);
	}
	else if(isset($_SESSION['dept_pic']) and isset($_SESSION['name'])) {
		$this->id = $_SESSION["name"];
		  $insert_log = array('id' => $this->xd,
							'user_id' =>$this->id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('logout'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
			//insert ke table trans log
			$this->Login->insert_log($insert_log);
		
		unset($_SESSION['dept_pic']);
	}
	else if(isset($_SESSION['admin']) and isset($_SESSION['name'])) {
		$this->id = $_SESSION["name"];
		  $insert_log = array('id' => $this->xd,
							'user_id' =>$this->id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('logout'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
			//insert ke table trans log
			$this->Login->insert_log($insert_log);
		
		unset($_SESSION['admin']);
	}
	else if(isset($_SESSION['sys_admin']) and isset($_SESSION['name'])) {
		$this->id = $_SESSION["name"];
		  $insert_log = array('id' => $this->xd,
							'user_id' =>$this->id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('logout'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
			//insert ke table trans log
			$this->Login->insert_log($insert_log);
			
    	unset($_SESSION['sys_admin']);
	}

		redirect('main');
	}
}
?>
